package com.school.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.school.mapper.FileMapper;
import com.school.mapper.StudentMapper;
import com.school.pojo.File;
import com.school.pojo.Student;
import com.school.service.StudentService;

@Service
@Transactional
public class StudentServiceImpl implements StudentService{
	
	@Autowired
	private StudentMapper studentMapper;
	
	@Autowired
	private FileMapper fileMapper;
	
	@Override
	public List<Student> findAll(int page, int pageSize, Student t) {
		PageHelper.startPage(page,pageSize);
		return studentMapper.findAll(t);
	}

	@Override
	public int add(Student student) {
		
		return studentMapper.add(student);
	}

	@Override
	public Student findbyId(int student_id) {
		
		return studentMapper.findbyId(student_id);
	}

	@Override
	public int edit(Student t) {
		
		return studentMapper.edit(t);
	}

	@Override
	public int delbatch(int[] id) {
		
		return studentMapper.delbatch(id);
	}

	@Override
	public Student findByAId(Integer account_id) {
		Student student2=new  Student();
		
		Student student=studentMapper.findByAId(account_id);
		if(student!=null) {
		File file= fileMapper.findbyId(student.getFile_id());
		
		student2.setName(student.getName());
		student2.setUrl(file.getUrl());
		}
		
		return student2;
	}

	@Override
	public Student findByAId2(Integer account_id) {
		
		Student student=studentMapper.findByAId(account_id);
		if(student!=null) {
		File file= fileMapper.findbyId(student.getFile_id());
		
		student.setName(student.getName());
		student.setUrl(file.getUrl());
		}
		
		return student;
	}

	@Override
	public int edits(Student t) {
		
		return studentMapper.edits(t);
	}

}
